<?php
/**
 * 剑指 Offer 06. 从尾到头打印链表
 * 输入一个链表的头节点，从尾到头反过来返回每个节点的值（用数组返回）。
 * Definition for a singly-linked list.
 * class ListNode {
 *     public $val = 0;
 *     public $next = null;
 *     function __construct($val) { $this->val = $val; }
 * }
 */

class ListNode {
    public $val = 0;
    public $next = null;
    function __construct($val) { $this->val = $val; }
}
class Solution {
    private $rs = [];
    /**
     * @param ListNode $head
     * @return Integer[]
     */
    function reversePrint($head) {
        if($head->next !== null){
            $this->reversePrint($head->next);
        }
        array_push($this->rs , $head->val) ;
        return $this->rs;
    }
}